package thread.concurrents;

import org.junit.Test;

/**
 * @Author: ycy
 * @CreateDate: 2020/10/9 15:27
 */
public class WaitAndNotify {

  @Test
  public void test1() {
    Object object = new Object();
    Thread thread = new Thread(new Runnable() {
      @Override
      public void run() {
        synchronized (object) {
          System.out.println("开始同步");
          try {
            object.wait(5000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
          System.out.println("同步结束");
        }
      }
    });

    Thread thread1 = new Thread(new Runnable() {
      @Override
      public void run() {
        synchronized (object) {
          System.out.println("线程2 开始同步");
          while (true) {
            try {
              Thread.sleep(1000);
              System.out.println();
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
          }
        }
      }
    });

    thread.start();
    thread1.start();
  }


}
